<template>
	<om-page :title="pageTitle">
		<view class="om_hd_fix">
			<om-topsearch 
				placeholder="请输入关键字" 
				:focus="true" 
				@confirm="confirm" 
				@input="confirm"></om-topsearch>
		</view>
		<view class="page__bd" style="padding-top: 100rpx;">
			<uni-list>
				<view v-for="(item, index) in datas" :key="index">
					<uni-list-item 
						@click="itemtap(item)"
						:showArrow="false" 
						:title="item.fullName">
					</uni-list-item>
				</view>
			</uni-list>
		 </view>
	</om-page>
</template>

<script>
	export default {
		data() {
			return {
				searchStr:"",
				datas:[],
				DICT_CLASSIFY_CODE:"",
				pageTitle:""
			}
		},
		created: function () {
		  this.initData = this._.debounce(this.initData, 300)
		},
		methods: {
			confirm(e){
				if (e.value) {
				  if (!this.searchStr || (this.searchStr && this.searchStr != e.value.trim())) {
					this.searchStr = e.value.trim()
					this.initData()
				  }
				}else{
					this.searchStr = ''
					this.datas= []
				}
			}, //点击选型确定input值
			initData(){
				let _that = this;
				_that.om.request('regions/getAddressCombox',{
					addressName: this.searchStr,
					classifyCode:_that.DICT_CLASSIFY_CODE || ""
				}).then(res=>{
					if (res) {
					  if (res.length) {
					    _that.datas = res
					  } else {
					    _that.datas= []
					  }
					}
				})
			},
			  itemtap: function(item) {
			    let address = {
			      id:item.id,
			      name: item.fullName,
			    }
			    uni.setStorage({
			      key: 'addr-cache',
			      data: address
			    })
			    //回主页面
			    uni.navigateBack();
			  }
		},
		onLoad(options) {
			this.pageTitle = options.title||"地址搜索"
			uni.setNavigationBarTitle({
			      title: this.pageTitle
			    })
			if(options){
				this.DICT_CLASSIFY_CODE = options.DICT_CLASSIFY_CODE ? options.DICT_CLASSIFY_CODE.toString():''
			}
		}
	}
</script>

<style>

</style>
